package es.juanc.threads.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class SimpleExecutor {

	public static void main(String args[]) {

		ThreadPoolExecutor es = (ThreadPoolExecutor) Executors.newFixedThreadPool(2);

		es.execute(new MyThread("A"));
		es.execute(new MyThread("B"));
		es.execute(new MyThread("C"));
		es.execute(new MyThread("D"));

//		try {
//
//		} catch (InterruptedException exc) {
//			System.out.println(exc);
//		}

		System.out.println(
				"getActiveCount: " + es.getActiveCount()
				+ "\ngetTaskCount: " + es.getTaskCount()
				+ "\ngetCompletedTaskCount: " + es.getCompletedTaskCount()
				+ "\ngetCorePoolSize: " + es.getCorePoolSize()
				+ "\ngetPoolSize: " + es.getPoolSize() );

		es.shutdown();
	}
}

class MyThread implements Runnable {

	String name;

	public MyThread(String n) {
		name = n;
	}

	public void run() {
		System.out.println( "soy '" + name + "' ..." );
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println( "... soy '" + name + "' FIN" );
	}
}
